package com.fr.data.core.db.handler;

import com.fr.report.script.Primitive;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public abstract class AbstractSQLTypeHandler
  implements SQLTypeHandler
{
  public void checkIsString(PreparedStatement paramPreparedStatement, int paramInt1, Object paramObject, int paramInt2)
    throws SQLException
  {
    if ((paramObject instanceof String) || (paramObject instanceof Number))
    {
      if (paramObject instanceof Number)
        paramObject = paramObject.toString();
      try
      {
        parseString(paramPreparedStatement, paramInt1, (String)paramObject);
      }
      catch (Exception localException)
      {
        paramPreparedStatement.setNull(paramInt1, paramInt2);
        if (!("".equals(paramObject)))
          throw new SQLException(localException.getMessage());
      }
    }
  }

  protected abstract void parseString(PreparedStatement paramPreparedStatement, int paramInt, String paramString)
    throws Exception;

  public Object dealNull4BasicType(ResultSet paramResultSet, int paramInt)
    throws SQLException
  {
    Object localObject = paramResultSet.getObject(paramInt);
    if (localObject == null)
      return Primitive.NULL;
    return localObject;
  }

  public Object getIntegerValue(ResultSet paramResultSet, int paramInt)
    throws SQLException
  {
    Object localObject = dealNull4BasicType(paramResultSet, paramInt);
    if (localObject == Primitive.NULL)
      return Primitive.NULL;
    return new Integer(localObject.toString());
  }
}